cmake: Undeprecate granular cache maintenance#681
Conversation
Not all of these memory locations need to be in regions of the same cacheability. Add back options to set the regions individually. WITH_DCACHE set to ON sets all regions to ON also for backwards compatibility with current behavior. Signed-off-by: Andrew Davis <afd@ti.com>
|
@glneo so, if cache ops are called on regions that are not-cached, then they should become no-op by the lower-level API. I don't understand how separate option helps. |
|
If the lower-level API is responsible for checking the cachability of the region I would be okay with that, but then we could just remove the |
edmooring
left a comment
There was a problem hiding this comment.
Given that this appears to be a straight re-introduction of previously-accepted code, it looks good to go.
@glneo Not all the cores have cache hardware available. In that case it makes sense to not compile cache related APIs. But if Cache hardware is available and for one region if its already used then why not let it handle other regions. We can argue that it would make un-necessary call to the API, that can slow down fw execution a bit. But other than that, I don't understand how introducing these options solves actual bug. If DCACHE was enabled that should have resolved any cache related bug. I am just trying to understand how this patch is helping in your case. |
I would agree with you that this is a micro-optimization that isn't an issue worth worrying about. So then why not remove the So either compile-time removing of these calls matters, in which case removing them as needed as this PR does would matters. Or it doesn't matter and I can send an update removing |
That is not how the library design works. Expecting users to provide empty stubs for the hardware their platform does not have is not a standard practice. We can always make exceptions, but it is not the case here. Anyway, my question is still unanswered, i.e. what kind of problem this patch is solving? I am trying to understand the motivation behind this patch. Is it like do you see significant improvement in firmware execution time or any bug that is fixed with this patch? @arnopo do you have any comment here? |
|
@glneo I am not against this patch. At least it is still improving performance by avoiding redundant cache calls. I just want to understand your use case. |
Sure it is, for instance libmetal always provides
That's all I was trying to fix here, but honestly I'm now thinking it should be up to the lower layer to decide if a cache operation is needed or not. Having it a compile time decision here just makes things less portable without having to change around build flags. To go from one platform with caches to one without, we shouldn't have to mess with platform specific build flags. Everything should be handled by libmetal, that is the point of libmetal, to make this library more portable. All the machine/system/platform specifics should be hidden down in the libmetal layer IMHO. |
Nope. Let's understand `metal_cache_{flush,invalidate} calls. I see the libmetal implementation, it is like this: metal_cache_flush() -> __metal_cache_flush() -> metal_machine_cache_flush.
I can always choose not to use the So, ideally if I build open-amp with WITH_DCACHE=off option then it should build. I don't think metal_cache* calls belong to that device.c file, and user should explicitly flush invalidate cache after using those dma ops, if their platform has the cache hardware. I will create PR to remove those calls from device.c, so users don't have to provide empty stubs.
The libmetal library should provide abstraction for sure but, should not enforce abstraction on the users. That means, user shouldn't have to provide implementation of the calls they are not planning to use in their applications / libraries. |
|
I'm feeling there is a very fundamental disagreement on the whole point of a library in general. A library provides a consistent and stable interface to perform some utility. The whole point of libmetal is to provide a portable interface for applications across different devices. Check the very first sentence of the very first paragraph of the libmetal readme:
Now you are saying you will just decide not to implement some APIs, not even as a stub, you break the basic promise of libmetal.
What are you talking about, users never have to provide implementations of these functions, we do, we provide libmetal to the users of our hardware. You and me are not users, we are vendors. And when we say we have an implementation of libmetal for our hardware our users expect us to provide the libmetal API, not just the parts we like. If some function isn't needed for some hardware (in this case if we don't have caches) then we make it a NOP, the compiler optimizes it out of the end application, no harm done. On the other hand if you don't provide even the stub and just break the API, well as you point out, even libmetal itself(!) doesn't build if the |
They are interfaces, not the implementation in many cases. If we wanted to enforce the stubs for metal_cache* functions, we wouldn't provide WITH_DCACHE option in the first place. Anyway, I don't think I need to answer here further due to fundamental misunderstanding. |
|
Hi, From my point of view:
Concerning cache management here is a proposal:
If we want to move cache configuration from OpenAMP to libmetal while preserving code optimization:
Option 1:
Option 2:
I would favor option 2, as it seems simpler and reflects the fact that the OpenAMP library should remain agnostic. The OS should be able to manage memory cacheability; otherwise, this can be handled in the machine setup. |
|
I'd like to avoid adding new Existing libmetal API should be good enough, implementation for a given hardware will fall into one of 3 buckets:
For the 3rd case the overhead of checking the memory cacheability would probably take longer than just issuing the cache operation unconditionally and letting the hardware ignore it. As I think our (TI) implementation would be the only one currently using mixed region cacheability, and we are okay with the overhead, this isn't an issue. Other implementations can always handle it they way they prefer. Should I update this PR to deprecate |
@arnopo exactly, We decided not to use metal_cache* APIs for the open-amp library by giving user a choice via WITH_DCACHE option. Now if we remove that option, then we are taking away that choice from the user and enforcing use of those APIs even if the hardware doesn't support it. I think we should discuss this on system-reference call and make a decision. I am against removing that option. I am okay with this patch.
I do not want to move CACHE configuration option to the Libmetal. It's correct in the open-amp library. I just don't want to remove it. |
That's fine, I'll join tomorrow and we can chat this out. In general though discussions here are nice as they provide better tracking for folks who might not be able to make the calls or are finding this thread sometime in the future. |
|
5/6/2026 OpenAMP system-reference call: |
Not all of these memory locations need to be in regions of the same cacheability. Add back options to set the regions individually. WITH_DCACHE set to ON sets all regions to ON also for backwards compatibility with current behavior.